package com.cssw.fyzb.busi.service.user;

import com.cssw.fyzb.busi.cache.Cache;
import com.cssw.fyzb.busi.cache.CacheKeys;
import com.cssw.fyzb.core.dao.user.DistrictDao;
import com.cssw.fyzb.core.model.dodb.District;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DistrictServiceImpl implements DistrictService {

    private static final Logger logger = LoggerFactory.getLogger(DistrictServiceImpl.class);

    @Autowired
    DistrictDao districtDao;

    @Override
    public District getByCode(String districtCode) {
        District district = null;
        try {
            district = Cache.get(CacheKeys.districtKey(districtCode), () -> districtDao.getByCode(districtCode));
        } catch (Exception e){
            logger.error("", e);
            //出现多次城市为空，现在这里做一个适配
            district = districtDao.getByCode(districtCode);
        }
        return district;
    }

}
